package com.example.tnot.Teacher.CoursePart.CourseInternal.ClassDetail.VpFragment.InternalAdapter;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.recyclerview.widget.RecyclerView;

import com.example.tnot.R;
import com.example.tnot.Teacher.CoursePart.CourseInternal.ClassDetail.ItemBean.MoreHome;

import java.util.List;

public class rv_classDetail_moreAdapter extends RecyclerView.Adapter<rv_classDetail_moreAdapter.ViewHolder>{
    private List<MoreHome> list;
    private rv_classDetail_moreAdapter adapter;
    public rv_classDetail_moreAdapter(List<MoreHome> list){
        this.list = list;
    }
    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_rv_class_more, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull rv_classDetail_moreAdapter.ViewHolder holder, @SuppressLint("RecyclerView") int position) {
        //获取数据的类型
        String type = list.get(0).getType();
        switch (type){
            case "任务":
                break;
            case "章节":
                holder.ll_chapter.setVisibility(View.VISIBLE);
                holder.ll_more.setVisibility(View.GONE);
                //任务设置不可见
                holder.itemView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        NavController navController = Navigation.findNavController(v);
                        Bundle bundle = new Bundle();
                        bundle.putString("chapterName",list.get(position).getCourseName());
                        navController.navigate(R.id.action_classDetailFragment_to_chapterDetailFragment,bundle);
                    }
                });
                break;
            case "更多":
                holder.ll_chapter.setVisibility(View.GONE);
                holder.ll_more.setVisibility(View.VISIBLE);
                //任务设置不可见
                break;
        }

        //更多页面
        holder.tv_name.setText(list.get(position).getName());
        //章节页面
        holder.iv_CourseCover.setImageResource(R.drawable.ic_course_cover);
        holder.tv_CourseName.setText(list.get(position).getCourseName());
        holder.tv_CourseTeacher.setText(list.get(position).getCourseTeacher());
        holder.tv_NumOfLearn.setText(list.get(position).getNumOfLearn()+"");
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder{
        TextView tv_name,tv_CourseName,tv_CourseTeacher,tv_NumOfLearn;
        ImageView iv_CourseCover;
        LinearLayout ll_more,ll_chapter;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            tv_name = itemView.findViewById(R.id.tv_name);
            ll_more = itemView.findViewById(R.id.ll_more);
            ll_chapter = itemView.findViewById(R.id.ll_chapter);
            tv_CourseName = itemView.findViewById(R.id.tv_CourseName);
            tv_CourseTeacher = itemView.findViewById(R.id.tv_CourseTeacher);
            tv_NumOfLearn = itemView.findViewById(R.id.tv_NumOfLearn);
            iv_CourseCover = itemView.findViewById(R.id.iv_CourseCover);
        }

    }

//    // 提供获取适配器的方法
//    public rv_classDetail_moreAdapter getAdapter(List<MoreHome> list) {
//        adapter = new rv_classDetail_moreAdapter(list);
//        return adapter;
//    }
}
